package com.sansecy.video.player;

import android.content.Context;
import android.net.Uri;
import android.view.Surface;

public class SimplePlayer implements IPlayer {
    public static final int EXOPLAYER = 1;
    public static final int IJKPLAYER = 2;
    public static final int MEDIAPLAYER = 3;
    IPlayer mPlayer;

    public SimplePlayer(Context context, int playerType) {
        if (playerType == IJKPLAYER) {
//            this.mPlayer = new IjkPlayer();
        } else if (playerType == EXOPLAYER) {
            this.mPlayer = new ExoPlayer(context);
        } else if (playerType == MEDIAPLAYER) {
            this.mPlayer = new ExoPlayer(context);
        } else {
            this.mPlayer = new ExoPlayer(context);
        }
    }

    @Override
    public void setUri(Uri uri) {
        mPlayer.setUri(uri);
        mPlayer.prepareAsync();
    }

    @Override
    public void setUri(Uri uri, String url) {
        mPlayer.setUri(uri, url);
    }

    @Override
    public void setVolume(float volume) {
        mPlayer.setVolume(volume);
    }

    @Override
    public long getDuration() {
        return mPlayer.getDuration();
    }

    @Override
    public long getCurrentPosition() {
        return mPlayer.getCurrentPosition();
    }

    @Override
    public void seekTo(long position) {
        mPlayer.seekTo(position);
    }

    @Override
    public boolean isPlaying() {
        return mPlayer.isPlaying();
    }

    @Override
    public void start() {
        mPlayer.start();
    }

    @Override
    public void pause() {
        mPlayer.pause();
    }

    @Override
    public void stop() {
        mPlayer.stop();
    }

    @Override
    public void release() {
        mPlayer.release();
    }

    @Override
    public void setDisplay(Surface surface) {
        mPlayer.setDisplay(surface);
    }

    @Override
    public void prepareAsync() {
        mPlayer.prepareAsync();
    }

    @Override
    public void setOnVideSizeChangeListener( OnVideoSizeChangedListener onVideoSizeChangedListener) {
        mPlayer.setOnVideSizeChangeListener(onVideoSizeChangedListener);
    }

    @Override
    public void setOnBufferListener(OnBufferListener onBufferListener) {
        mPlayer.setOnBufferListener(onBufferListener);
    }

    @Override
    public void setOnCompletionListener(OnCompletionListener onCompletionListener) {
        mPlayer.setOnCompletionListener(onCompletionListener);
    }

    @Override
    public int getBufferPercentage() {
        return mPlayer.getBufferPercentage();
    }

    @Override
    public void setSubtitle(String uri, String mimeType) {
        mPlayer.setSubtitle(uri, mimeType);
    }

    @Override
    public Object getPlayer() {
        return mPlayer.getPlayer();
    }

    @Override
    public IPlayer getIPlayer() {
        return mPlayer;
    }

    @Override
    public boolean isAudio() {
        return mPlayer.isAudio();
    }

    @Override
    public void setOnErrorListener(onErrorListener onErrorListener) {
        mPlayer.setOnErrorListener(onErrorListener);
    }

    private static final String TAG = "SimplePlayer-App";

}
